package com.zero.mxshengadmin.modules.website.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zero.mxshengadmin.common.exception.RRException;
import com.zero.mxshengadmin.modules.website.dao.WebsiteCompanyInfoDao;
import com.zero.mxshengadmin.modules.website.entity.WebsiteCompanyInfoEntity;
import com.zero.mxshengadmin.modules.website.service.WebsiteCompanyInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * Created by aicaikeji on 2019/4/3.
 */

@Service("websiteCompanyInfoService")
public class WebsiteCompanyInfoServiceImpl extends ServiceImpl<WebsiteCompanyInfoDao,WebsiteCompanyInfoEntity> implements WebsiteCompanyInfoService {

    @Resource
    private WebsiteCompanyInfoDao websiteCompanyInfoDao;
    /**
     * 添加公司信息
     * @param entity
     * @return
     */
    @Override
    public void save(WebsiteCompanyInfoEntity entity) {
        boolean save = this.insert(entity);
        if (!save) throw new RRException("操作失败");
    }


    /**
     * 查询公司信息
     * @param id
     * @return
     */
    @Override
    public WebsiteCompanyInfoEntity getById(long id) {
        WebsiteCompanyInfoEntity entity = this.selectById(id);
        if (entity == null) {
            throw  new RRException("操作失败");
        }else {
            return entity;
        }
    }

    /**
     * 获取一条信息
     * @return
     */
    @Override
    public WebsiteCompanyInfoEntity getOneItem() {
        return websiteCompanyInfoDao.getOneItem();
    }


    /**
     * 更新公司信息
     * @param entity
     * @return
     */
    @Override
    public void update(WebsiteCompanyInfoEntity entity) {
        boolean update = this.updateById(entity);
        if (!update) throw new RRException("操作失败");
    }


    /**
     * 删除公司信息
     * @param ids
     * @return
     */
    @Override
    public void removeByIds(Long[] ids) {
        this.deleteBatchIds(Arrays.asList(ids));
    }
}
